<?php
/*
 * @Author: your name
 * @Date: 2020-10-22 11:04:19
 * @LastEditTime: 2020-12-31 17:14:24
 * @LastEditors: Please set LastEditors
 * @Description: 端口伪装
 * @FilePath: /special/application/api/service/client_login/DisguiseLoginService.php
 */
namespace app\api\service\client_login;

use app\common\definition\InternetProtocolsDefinition;
use app\common\exception\CustomException;
use app\common\service\module_manage\disguise\HostGuiseConfig;
use app\common\service\module_manage\disguise\HostGuisePort;

class DisguiseLoginService extends LoginService
{
    public $module = 'disguise';
    /**
     * @name: 端口伪装接口
     * @Param:
     * @Description:
     * @Author: foo
     * @Date: 2019-12-07 15:02:42
     */
    function login ()
    {
        
        $HostGuiseConfig = new HostGuiseConfig();
        $config = $HostGuiseConfig->findOne($this->host_id);
        if($config['guise_status'] == 0)
        {
            return [];
        }

        $HostGuisePort = new HostGuisePort();
        $guisePort = $HostGuisePort->info($this->host_id);
        
        if(empty($guisePort))
        {
            throw new CustomException('未找到disguise设置', 422);
        }

        $return = array_map(function ($v)
        {
            return [
                'Proto' => $v['protocols'] == InternetProtocolsDefinition::TCP_PROTOCOL ? 'tcp' : 'udp',
                'Port' => $v['port'],
            ];
        }, $guisePort);

        return $return;
    }
}